#pragma once
#include <iostream>
#include <mutex>

namespace Zsw
{
	class Singleton
	{
	public:
		static Singleton& GetSingleton()
		{
			return Singleton::singleton;
		}

	private:
		Singleton() {}
		Singleton(const Singleton&) = delete;
		Singleton& operator=(const Singleton&) = delete;

		static Singleton singleton;
	};

	Singleton Singleton::singleton;
}

class Singleton
{
public:
	static Singleton* GetSingleton()
	{
		{
			if(Singleton::singleton == nullptr)
			{
				std::unique_lock<std::mutex> ul(mtx);
				if (Singleton::singleton == nullptr)
				{
					Singleton::singleton = new Singleton();
				}
			}
		}
		return Singleton::singleton;
	}

private:
	Singleton() {}
	Singleton(const Singleton&) = delete;
	Singleton& operator=(const Singleton&) = delete;
	static Singleton* singleton;
	static std::mutex mtx;
};
static Singleton* singleton = nullptr;
static std::mutex mtx;
